// pages/sell_info/sell_info.js
const db = wx.cloud.database();
const _ = db.command
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:null
  },
  onLoad: function (options) {
      //根据用户的appid去寻找订单信息
      this.init();
  },
  //寻找订单信息
  init:function(){
    let that=this;
    db.collection('sell_list').where({
      sell_openid: app.globalData.openid,
    })
      .get({
        success: function (res) {
          console.log(res.data)
          that.setData({
            list:res.data
          })
          that.add_info();
        }
      })
  },
  //往对象数组里面添加  图片地址   名字   价格   等信息
  add_info:function(){
    let that=this;
    for (let i = 0; i < that.data.list.length;i++){
      db.collection('users').doc(that.data.list[i].shop_id).get().then(res => {
        // res.data 包含该记录的数据
        console.log(res.data);
        let name = "list[" + i +"]"
        that.setData({
          [name]: Object.assign(that.data.list[i],{"name":res.data.name,"src":res.data.src,"species":res.data.species,"content":res.data.content,"price":res.data.price})
        })
        console.log(that.data.list[i]);
      })
    }
  }


})